<span class="msg" id="msgSort">Seřadit</span>
<div class="center">
<table class="centered medium-table">

<?php

$sort_field = $_GET['sort'];
$ascdesc = $_GET['ascdesc'];
if(!isset($sort_field)) $sort_field = "prijmeni";
if(!isset($ascdesc)) $ascdesc = 0;

$link = redirect_str(PAGE_PLAYERS).add_par("ascdesc=".(!$ascdesc));
echo "<thead>";
echo "<tr>";
    echo "<th class='link'><a class='preloader' href=\"".$link.add_par("sort=prijmeni")."\" onmouseover=\"MyTip('msgSort', 'help')\" onmouseout='UnTip()'>jméno ".getSortIcon($sort_field == "prijmeni", $ascdesc)."</a></th>";
    echo "<th class='link'><a class='preloader' href=\"".$link.add_par("sort=post")."\" onmouseover=\"MyTip('msgSort', 'help')\" onmouseout='UnTip()'>post ".getSortIcon($sort_field == "post", $ascdesc)."</a></th>";
    echo "<th class='link'><a class='preloader' href=\"".$link.add_par("sort=datum")."\" onmouseover=\"MyTip('msgSort', 'help')\" onmouseout='UnTip()'>věk ".getSortIcon($sort_field == "datum", !$ascdesc)."</a></th>";
    echo "<th class='link'><a class='preloader' href=\"".$link.add_par("sort=utkani")."\" onmouseover=\"MyTip('msgSort', 'help')\" onmouseout='UnTip()'>utkání ".getSortIcon($sort_field == "utkani", $ascdesc)."</a></th>";
    echo "<th class='link'><a class='preloader' href=\"".$link.add_par("sort=branky")."\" onmouseover=\"MyTip('msgSort', 'help')\" onmouseout='UnTip()'>góly ".getSortIcon($sort_field == "branky", $ascdesc)."</a></th>";
    echo "<th class='link'><a class='preloader' href=\"".$link.add_par("sort=zk")."\" onmouseover=\"MyTip('msgSort', 'help')\" onmouseout='UnTip()'>žk ".getSortIcon($sort_field == "zk", $ascdesc)."</a></th>";
    echo "<th class='link'><a class='preloader' href=\"".$link.add_par("sort=ck")."\" onmouseover=\"MyTip('msgSort', 'help')\" onmouseout='UnTip()'>čk ".getSortIcon($sort_field == "ck", $ascdesc)."</a></th>";
    echo "<th>info</th>";
echo "</tr>";
echo "</thead>";
?>
<tbody>
<?
    $query = getPlayersStats($sort_field, $ascdesc, SEASON);
    
    $idx = 0;
    $age_sum = 0;
    
    while($fetch = MySQL_Fetch_Array($query)){
      $id = $fetch["id_hrace"];
      $name = $fetch["jmeno"];
      $surname = $fetch["prijmeni"];
      $age = $fetch["vek"];
      $post = $fetch["post"];
      $post_long = $fetch["post_long"];
      $matches = $fetch["utkani"];
      $goals = $fetch["branky"];
      $yellows = $fetch["zk"];
      $reds = $fetch["ck"];
      $photo = $fetch["foto"];
      $host = $fetch["hostovani"];
      $birthday = DateFormat::format($fetch["narozen"], DF_DDMMYYYY);
      
      require("./inc/player_modal.php");
      
      if($idx % 2 == 0){ echo "<tr>"; }
      else { echo "<tr class='second'>"; }
      echo "<td class='lefted'>$surname $name</td>";
      echo "<td>$post</td>";
      echo "<td>$age</td>";
      echo "<td>$matches</td>";
      echo "<td>$goals</td>";
      echo "<td>$yellows</td>";
      echo "<td>$reds</td>";
      echo "<td><a onclick=\"popup_show('player_popup".$id."', 'player_popup_drag".$id."', 'player_popup_exit".$id."', 'screen-center',         0,   0);\" class='button'>PROFIL</a></td>";
      echo "</tr>";
      $idx ++;
      if($age != "") {
      	$age_sum += $age;
      }
    }
	
?>
</tbody>
</table>
<?
if($idx > 0) {
	$average = round($age_sum / $idx, 1);
    echo "<div style='font-size: 10px; margin-top: 5px;'><i>Věkový průměr hráčů v nynějším mužstvu je ".$average." let</i></div>";
}
?>
</div>
